<template>
	<view class="container">
		<!-- 素材分类 -->
		<scroll-view 
			scroll-x 
			class="category-scroll"
			:show-scrollbar="false"
		>
			<view 
				class="category-item" 
				v-for="(item, index) in categories" 
				:key="index"
				:class="{ active: currentCategory === item.value }"
				@tap="switchCategory(item.value)"
			>
				<text>{{item.label}}</text>
			</view>
		</scroll-view>
		
		<!-- 素材列表 -->
		<scroll-view 
			scroll-y 
			class="material-list"
			@scrolltolower="loadMore"
			refresher-enabled
			:refresher-triggered="isRefreshing"
			@refresherrefresh="onRefresh"
		>
			<view 
				class="material-item" 
				v-for="(item, index) in materialList" 
				:key="index"
			>
				<image :src="item.image" mode="aspectFill" class="material-img"></image>
				<view class="material-info">
					<text class="title">{{item.title}}</text>
					<text class="desc">{{item.desc}}</text>
					<view class="action-bar">
						<text class="size">{{item.size}}</text>
						<button class="download-btn" @tap="downloadMaterial(item)">下载</button>
					</view>
				</view>
			</view>
			
			<!-- 加载更多 -->
			<view class="loading-more" v-if="hasMore">
				<text>加载中...</text>
			</view>
			<view class="no-more" v-else>
				<text>没有更多了</text>
			</view>
			
			<!-- 空状态 -->
			<view class="empty-state" v-if="materialList.length === 0">
				<image src="/static/images/empty.png" mode="aspectFit" class="empty-img"></image>
				<text class="empty-text">暂无推广素材</text>
			</view>
		</scroll-view>
	</view>
</template>

<script setup>
import { ref } from 'vue'

// 素材分类
const categories = [
	{ label: '全部', value: 'all' },
	{ label: '商品图片', value: 'product' },
	{ label: '活动海报', value: 'poster' },
	{ label: '推广文案', value: 'text' },
	{ label: '视频素材', value: 'video' }
]

// 当前分类
const currentCategory = ref('all')

// 是否正在刷新
const isRefreshing = ref(false)

// 是否还有更多数据
const hasMore = ref(true)

// 素材列表
const materialList = ref([
	{
		image: 'https://img.alicdn.com/imgextra/i4/O1CN01XCiY1B1nx2Xh2Z9tP_!!6000000005155-0-tps-1316-736.jpg',
		title: '商品主图',
		desc: '高清商品展示图，适合朋友圈分享',
		size: '2.5MB',
		url: 'https://example.com/material1.jpg'
	},
	{
		image: 'https://img.alicdn.com/imgextra/i2/O1CN01F0MA5j1zXb0XcYV1F_!!6000000006733-0-tps-1316-736.jpg',
		title: '活动海报',
		desc: '双11活动宣传海报',
		size: '3.8MB',
		url: 'https://example.com/material2.jpg'
	},
	{
		image: 'https://img.alicdn.com/imgextra/i3/O1CN01Z5paLt1goYDdHEzSU_!!6000000004150-0-tps-1316-736.jpg',
		title: '推广文案',
		desc: '商品卖点文案合集',
		size: '1.2MB',
		url: 'https://example.com/material3.txt'
	}
])

// 切换分类
const switchCategory = (category) => {
	currentCategory.value = category
	// 重置列表并重新加载
	materialList.value = []
	hasMore.value = true
	loadMaterials()
}

// 加载素材列表
const loadMaterials = () => {
	// 这里可以添加根据分类加载素材列表的接口调用
}

// 加载更多
const loadMore = () => {
	if (!hasMore.value) return
	
	// 这里可以添加加载更多素材的接口调用
	setTimeout(() => {
		hasMore.value = false
	}, 1000)
}

// 下拉刷新
const onRefresh = () => {
	isRefreshing.value = true
	// 重置列表并重新加载
	materialList.value = []
	hasMore.value = true
	
	setTimeout(() => {
		isRefreshing.value = false
		loadMaterials()
	}, 1000)
}

// 下载素材
const downloadMaterial = (material) => {
	uni.showLoading({
		title: '下载中...'
	})
	
	// 这里可以添加下载素材的接口调用
	setTimeout(() => {
		uni.hideLoading()
		uni.showToast({
			title: '下载成功',
			icon: 'success'
		})
	}, 1000)
}
</script>

<style>
.container {
	min-height: 100vh;
	background-color: #F5F5F5;
}

/* 分类滚动样式 */
.category-scroll {
	background-color: #FFFFFF;
	padding: 20rpx 30rpx;
	white-space: nowrap;
}

.category-item {
	display: inline-block;
	padding: 10rpx 30rpx;
	margin-right: 20rpx;
	font-size: 28rpx;
	color: #666;
	background-color: #F5F5F5;
	border-radius: 30rpx;
}

.category-item.active {
	color: #FFFFFF;
	background-color: #D02B29;
}

/* 素材列表样式 */
.material-list {
	height: calc(100vh - 100rpx);
}

.material-item {
	background-color: #FFFFFF;
	margin: 20rpx;
	padding: 20rpx;
	border-radius: 10rpx;
}

.material-img {
	width: 100%;
	height: 300rpx;
	border-radius: 8rpx;
	margin-bottom: 20rpx;
}

.material-info {
	display: flex;
	flex-direction: column;
}

.title {
	font-size: 32rpx;
	color: #333;
	font-weight: bold;
	margin-bottom: 10rpx;
}

.desc {
	font-size: 28rpx;
	color: #666;
	margin-bottom: 20rpx;
}

.action-bar {
	display: flex;
	justify-content: space-between;
	align-items: center;
}

.size {
	font-size: 24rpx;
	color: #999;
}

.download-btn {
	width: 160rpx;
	height: 60rpx;
	line-height: 60rpx;
	text-align: center;
	background-color: #D02B29;
	color: #FFFFFF;
	border-radius: 30rpx;
	font-size: 24rpx;
}

/* 加载更多样式 */
.loading-more, .no-more {
	text-align: center;
	padding: 20rpx 0;
	font-size: 24rpx;
	color: #999;
}

/* 空状态样式 */
.empty-state {
	padding: 100rpx 0;
	text-align: center;
}

.empty-img {
	width: 200rpx;
	height: 200rpx;
	margin-bottom: 20rpx;
}

.empty-text {
	font-size: 28rpx;
	color: #999;
}
</style> 